package v1

import (
	"github.com/gin-gonic/gin"
	"jmicro/app/jshop/api/internal/controller"
	"jmicro/app/jshop/api/internal/domain/request"
	gin2 "jmicro/app/pkg/translator/gin"
	"jmicro/pkg/common/core"
)

func (us *userServer) Regisger(ctx *gin.Context) {
	regForm := request.RegisterForm{}
	if err := ctx.ShouldBind(&regForm); err != nil {
		gin2.HandleValidatorError(ctx, err, controller.Trans)
		return
	}
	userDTO, err := us.userSrv.Register(ctx, regForm.Mobile, regForm.PassWord, regForm.Code)
	if err != nil {
		core.WriteResponse(ctx, err, nil)
		return
	}

	core.WriteResponse(ctx, nil, gin.H{
		"id":         userDTO.ID,
		"nick_name":  userDTO.NickName,
		"token":      userDTO.Token,
		"expired_at": userDTO.ExpiresAt,
	})
}
